<template>
  <div  class="wrapper">
    <BreakSpace label="基本信息" :containerStyle="{ marginBottom: '15px' }" />
    <div style="height:300px">
      <FormPanel
        ref="from"
        :list="initForm"
        :cols="3"
        :formType="value.type"
        :labelWidth="120"
        :isSubmitBtn="false"
        :collapse="false"
        @formChange="changeHandle"
      />
    </div>

    <BreakSpace label="签收信息" :containerStyle="{ marginBottom: '15px' }" />
    <FilterTable
      height="300"
      ref="tablePeij"
      :columns="partColumns"
      :isSelectColumn="isSelectColumn"
      selectionType="single"
      :isMemoryPagination="true"
      :onSyncTableData="syncPjFun"
      :datakey="'records'"
      :isToperInfo="false"
      :onColumnsChange="partColumns => (this.partColumns = partColumns)"
      columnsRef="notification_maintain_info_02"
    >
    </FilterTable>
    <div class="dialogBottmView">
      <el-button :loading="loadingFlag" @click="saveDialog()" type="primary">签 收</el-button>
      <el-button @click="closeDialog('closeDialog')">返 回</el-button>
    </div>
  </div>
</template>

<script>
import { getDetailData, postSave } from '@/api/partsmanage/shipment/query';
import { dictionary } from '@/utils/dictMixin';
export default {
  name: 'shipmentreceiveinfo',
  mixins: [dictionary],
  props:{
    value: {
      type: Object,
      data: Object,
      required: true
    },
  },
  data() {
    this.saveData=null;
    return {
      initForm : this.initFormFun(),
      partColumns: this.creatHeaderPartRoleColumns(),
      isSelectColumn: false,
      formData:{},
      id: '',
      loadingFlag: false,
      saveInfo: {},
      detailList: []
    }
  },
  created() {
    this.init(this.value.data)
  },
  methods: {
    init(data) {
      this.id = data.id
      this.initForm.forEach(x => {
        x.initialValue = data[x.fieldName];
      });
      getDetailData({ "id": this.id }).then(response => {
        var list = response.data.records
        this.detailList = list
        if(response.resultCode === 200){
          this.$nextTick(()=>{
            this.$refs.tablePeij.EXECUTE_INSERT(list)
          })
        }
      })
    },
    initFormFun() {
      return [
        {
          type: 'INPUT',
          label: '经销商代码',
          fieldName: 'ownerCode',
          placeholder: '请输入',
          initialValue: '',
          disabled: true,
        },
        {
          type: 'INPUT',
          label: '经销商名称',
          fieldName: 'sasa1',
          placeholder: '请输入',
          initialValue: '',
          disabled: true,
        },
        {
          type: 'INPUT',
          label: '签收日期',
          fieldName: 'bsqcrq',
          placeholder: '请输入',
          initialValue: '',
          disabled: true,
        },
        {
          type: 'INPUT',
          label: 'SAP发运单号',
          fieldName: 'bsysdh',
          placeholder: '请输入',
          initialValue: '',
          disabled: true,
        },
        {
          type: 'INPUT',
          label: '发运日期',
          fieldName: 'bsfyrq',
          placeholder: '请输入',
          initialValue: '',
          disabled: true,
        },
        {
          type: 'INPUT',
          label: '物流公司',
          fieldName: 'sasa5',
          placeholder: '请输入',
          initialValue: '',
          disabled: true,
        },
        {
          type: 'INPUT',
          label: '发运单号',
          fieldName: 'bsydxh',
          placeholder: '请输入',
          initialValue: '',
          disabled: true,
        },
        {
          type: 'INPUT',
          label: '发运方式',
          fieldName: 'btyslx',
          placeholder: '请输入',
          initialValue: '',
          disabled: true,
        },
        {
          type: 'INPUT',
          label: '预计到货日期',
          fieldName: 'bsyjdd',
          placeholder: '请输入',
          initialValue: '',
          disabled: true,
        }
      ]
    },
    creatHeaderPartRoleColumns() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 80,
          sorter: true,
          render: props => {
            return <span>{props.$index + 1}</span>;
          }
        },
        // { title: '厂家发运仓库代码', dataIndex: 'sasa11', sorter: true },
        { title: '厂家发货仓库名称', dataIndex: 'bsckmc', sorter: true },
        { title: '配件代码', dataIndex: 'bjxmbh', sorter: true },
        { title: '配件名称', dataIndex: 'bjzwmc', sorter: true },
        { title: '订单号', dataIndex: 'bsddwj', sorter: true, width: 200 },
        { title: '发运数量', dataIndex: 'bsfysl', sorter: true },
        { title: '签收数量', dataIndex: 'bssjsl', sorter: true },
        // { title: '入库数量', dataIndex: 'rksl', sorter: true },
        { title: '差异数量', dataIndex: 'bszssl', sorter: true },
      ]
    },
    //取消操作
    closeDialog(type) {
      this.$emit('close', {visible: false, type: type});
    },
    changeHandle(val){
      this.saveData=val
    },
    syncPjFun(details){
      this.formData.details = details
    },
    async saveDialog() {
      this.saveInfo.id = this.id
      this.saveInfo.detailList = this.detailList
      this.loadingFlag = true;
      let res=await postSave(this.saveInfo)
      if (res.resultCode === 200) {
        this.$notify.success({title: '提示信息',message:'保存成功!'});
        this.loadingFlag = false;
        this.closeDialog('refresh')
      } else {
        this.loadingFlag = true;
        this.$notify.error({title: '提示信息',message:res.errMsg||'保存失败!'});
      }
    }
  }
}
</script>
